/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;


import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import model.Model;
import tiendagui.internal.JInternalFrameImpl;
import entities.vo.ArticuloVO;
import entities.vo.ItemTablaVO;

/**
 *
 * @author Jhonny
 */
public abstract  class Controller {
    protected JInternalFrameImpl            dialog;
    protected Model                         model;
    protected Logger						logger;


    public Controller(JInternalFrameImpl dialog,Model model) {
        this.dialog = dialog;
        this.model = model;
        logger = Logger.getLogger(getClass().getName());
    }
    public Controller() {
    	logger = Logger.getLogger(getClass().getName());
    }
    public abstract  void initComponentView()throws Exception;
    public void cerrar(){
        dialog.setVisible(false);
    }
    protected  void initDatosTablaArticulos(JTable table, List<ArticuloVO> articulos){
    	List<ItemTablaVO> list = new LinkedList<ItemTablaVO>();
        if(articulos!=null){            
        	list.addAll(articulos);
        }
        initDatosTabla(table, list);
    }
    protected  void initDatosTabla(JTable table, List<ItemTablaVO> articulos){
        deleteTable(table);
        if(articulos!=null){
            for (ItemTablaVO itemTabla : articulos) {
                ((DefaultTableModel)table.getModel()).addRow(itemTabla.toVector());
            }
        }
    }
    protected void deleteTable(JTable table){
        int countRow = ((DefaultTableModel)table.getModel()).getRowCount();
        for (int i = 0; i < countRow; i++) {
            ((DefaultTableModel)table.getModel()).removeRow(0);
        }
    }
  
}
